package Classes.GameViews.ViewIcons// ActionScript file
{
	import Classes.GameDatas.GD_Mission;
	import Classes.GameDatas.GD_Player;
	import Classes.GameUtils.Deal_SpecialMission;
	import Classes.GameUtils.GU_dealPower;
	import Classes.GameViews.ViewPanels.VP_Mission;
	import Classes.GameViews.ViewPanels.VP_errorPanel;
	import Classes.Interfaces.I_Observer;
	import Classes.Managers.M_Communication;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.filters.BitmapFilterQuality;
	import flash.filters.GlowFilter;

	public class VI_Mission extends ViewIcon implements I_Observer
	{
		private var _mission:GD_Mission;
		public function VI_Mission(mission:GD_Mission):void
		{
			super(mission.sourceName,mission.picName);
			this._mission=mission;
			this.init();
		}
		
		private function init():void
		{
			this.showState();
			this.showStep();
			this.mission.addObserver("missionState",this);
			this.mission.addObserver("missionStep",this);
			this.addListener();
			this.filters=[new GlowFilter(0xffffff,1,4,4,5,BitmapFilterQuality.LOW)];
		}
		
		private function addListener():void
		{
			this.addEventListener(MouseEvent.CLICK,clickHandler);
			this.addEventListener(MouseEvent.ROLL_OVER,overHandler);
			this.addEventListener(MouseEvent.ROLL_OUT,outHandler);
		}
		
		private function removeListener():void
		{
			this.removeEventListener(MouseEvent.CLICK,clickHandler);
			this.removeEventListener(MouseEvent.ROLL_OVER,overHandler);
			this.removeEventListener(MouseEvent.ROLL_OUT,outHandler);
		}
		
		private function clickHandler(e:MouseEvent):void
		{
			//系统权限---点击任务
//			Deal_SpecialMission.instance.hanldOverMisstion(null,null);
//			Deal_SpecialMission.instance.hanldMIssion(null);
//			return;
			
			//整个游戏的权限由自己控制   10000204系统权限---点击任务
			if(null==GD_Player.instance.playPowerObj[10000204] || 0==GD_Player.instance.playPowerObj[10000204])
			{
				VP_errorPanel.instance.noPowerMsg();
				return;
			}
			
			GU_dealPower.instance.hanldMission(this.mission.missionType);
			
			if(this.mission.missionStatue==0)
			{
				M_Communication.instance.send(12201,{missionID:this.mission.missionType,statue:0});
			}else{
				VP_Mission.instance.setMission(this.mission);
			}
			
		}
		
		private function overHandler(e:MouseEvent):void
		{
			this.addFilter();
		}
		
		private function outHandler(e:MouseEvent):void
		{
			this.removeFilter();
			this.filters=[new GlowFilter(0xffffff,1,4,4,5,BitmapFilterQuality.LOW)];
		}
		
		private function addFilter():void
		{
			var filter:GlowFilter=new GlowFilter(0xffffff,1,5,5,7,BitmapFilterQuality.HIGH);
			var filters:Array=[filter];
			this.filters=filters;
		}
		
		private function removeFilter():void
		{
			this.filters=null;
		}
		
		public function touchObserve(observeType:String):void
		{
			switch(observeType)
			{
				case "missionState":
					this.showState();
					break;
				case "missionStep":
					this.showStep();
					break;
			}
		}
		
		private function showState():void
		{
			this.setState(this.mission.missionState);
			
			//newGuide
			if(GU_dealPower.instance.isNewGuideMis(this.mission.missionType))
			{
				if(this.mission.missionState=="new" || this.mission.missionState=="over")
				{
//					GU_dealPower.instance.hanldNewMis(this.mission.missionType);
					if(this.mission.missionType==11000009 || this.mission.missionType==11000012||this.mission.missionType==11000010  || this.mission.missionType==11000004){
						GU_dealPower.instance.dealMis(this.mission.missionType);
					}
					if(this.mission.missionState=="over" && (this.mission.missionType==11000001 || this.mission.missionType==11000006 || this.mission.missionType==11000005))
					{
						GU_dealPower.instance.dealMis(this.mission.missionType);
					}
						
				}else{
//					GU_dealPower.instance.hideMisNewGuide();
					GU_dealPower.instance.dealMis(this.mission.missionType);
				}
			}
			
		}
		private function showStep():void
		{
			this.setStep(this.mission.missionStep);
		}
		
		public function cleanAllObserves():void
		{
			this.mission.removeObserver("missionState",this);
			this.mission.removeObserver("missionStep",this);
		}
		
		override public function release():void
		{
			super.release();
			this.cleanAllObserves();
			this._mission=null;
		}

		public function get mission():GD_Mission
		{
			return _mission;
		}

	}
}